package com.zh.demo04.verifycode.sms;

import com.alibaba.fastjson.JSON;
import com.zh.demo04.common.ApiResult;
import com.zh.demo04.verifycode.VerifyCode;
import com.zh.demo04.verifycode.VerifyCodeService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * 手机验证码 业务逻辑
 */
@Slf4j
public class SmsCodeService extends VerifyCodeService {

    public SmsCodeService(int codeLength, int expireSecond) {
        this.codeLength = codeLength;
        this.expireSecond = expireSecond;
    }


    @Override
    protected void sendCode(VerifyCode verifyCode, HttpServletResponse response) throws IOException {
        SmsCode smscode = (SmsCode) verifyCode;
        log.info("验证码 smsCode = " + smscode.getCode());
        //将验证码写入response
        response.setContentType("text/plain;charset=UTF-8");
        response.getWriter().write(JSON.toJSONString(ApiResult.success(smscode.getCode(), "短信验证码发送成功")));
    }
}
